import { GetRequest, PostRequest, PutRequest, DeleteRequest } from '@/utils/request'

export type BIWDSettingsType = {
  default: string
  en?: null
  key: string
  max: string
  min: string
  name: string
  param: string
  step?: string
  type: string
  value: number | string
  zh?: null
  enumValues?: []
}

/**
 * 获取程序列表数据
 */
export type ProgramsGroupListType = {
  key: string
  name: string
  param: string
  programs: AvailableProgramType[]
}
export type ProgramsOptionsType = {
  ENName: string
  default: string
  desc: string | null
  key: string
  max: string
  min: string
  name: string
  param: string
  step: string
  type: string
  unit: string
  enumValues?: EnumValuesType[]
  value?: string
}
export type OptionsEnumValuesType = {
  ENName: string
  bshValue: string
  machineValue: string
  name: string
}

export type EnumValuesType = {
  bshValue?: string | number
  machineValue?: number
  name?: string | number
  value?: string | number
  ENName?: string | null
}

export function getNewProgramScope(haId: string) {
  return PostRequest<{ programGroup: ProgramsGroupListType[] }>(
    `/hcaextension/hcmini/v1/center/getControlNew/programs/${haId}`
  )
}

/**
 * 获取available数据
 */
export type NewAvailableType = {
  brand: string
  name: string
  type: string
  vib: string
  programs: AvailableProgramType[]
}
export type AvailableProgramType = {
  ENName: ''
  desc: string | null
  isSupportDelayStart: true
  isSupportPause: true
  isSupportRun: true
  isSupportStop: true
  key: string
  name: string
  param: string
  url: null
  options: ProgramsOptionsType[]
}
export function getNewProgramAvailable(haId: string) {
  return PostRequest<NewAvailableType>(`/hcaextension/hcmini/v1/center/getAvailableNew/programs/${haId}`)
}

/**
 * 选择程序
 */
export function selectNewProgram(haId: string, data: {}) {
  return PostRequest(`/hcaextension/hcmini/v1/center/openControlNew/programs/${haId}`, { payload: data })
}

/**
 * get家电Profile文件
 */
export type ProfileVersionType = {
  profileversion: string
  serverprofileversion: VersionContentType
}
export type VersionContentType = {
  changeLog: string
  devtype: string
  upgradeflag: number
  url: string
  version: string
}
export function getProfileVersion(haId: string) {
  return GetRequest<ProfileVersionType>(`/api/OEMhomeappliances/queryFirmwareVersion/${haId}`)
}

/**
 * 升级家电Profile文件
 */
export function upgradeProfileVersion(haId: string, data: {}) {
  return PostRequest(`/api/OEMhomeappliances/firmwareUpgrade/${haId}`, { data })
}

/**
 * get家电Firmware文件
 */
export type FirmwareVersionType = {
  hwcode: string
  pid: string
  upgradingVersion: string
  version: string
  serverVersion: VersionContentType
}
export function getFirmwareVersion(haId: string) {
  return GetRequest<FirmwareVersionType[]>(`/api/OEMhomeappliances/queryMcuFirmwareVersion/${haId}`)
}

/**
 * 升级家电Firmware文件
 */
export function upgradeFirmwareVersion(haId: string, data: {}) {
  return PostRequest(`/api/OEMhomeappliances/firmwareMcuUpgrade/${haId}`, { data })
}

/**
 * oem 双指令升级
 */
export function upgradeCombinationFirmware(haId: string, data: {}) {
  return PostRequest(
    `/api/OEMhomeappliances/combinationUpgrade/${haId}`,
    { data },
    {
      ignoreErrorTips: true,
    }
  )
}
